<%@ page contentType="text/html;charset=utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
	<head>
		<title>公寓楼显示</title>
		<link rel="stylesheet"
			href="<%=request.getContextPath()%>/css/common.css" type="text/css" />
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/apartmentViewAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/engine.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/util.js'></script>
		<script type="text/javascript">
		 var DMS_ROOT = '<%=request.getContextPath()%>';
		/**
		* 给apart select框赋值的
		*/

			var gaptInfo=""; //这个gaptInfo是全局变量
			var apartamount; //定义查询出的公寓总条数
			
			function setApartList() {
					 apartmentViewAction.getAllApartInfo(mycallback);
				}
			
			var mycallback = function setList(aptValue)//回调函数
				{
						gaptInfo =aptValue;
						apartamount = gaptInfo.length; //给公寓总条数赋值
						var s = $("aptName");
					 	DWRUtil.removeAllOptions(s); 
						s.options[0] = new Option("请选择公寓",'0');
					for ( var i = 1; i < aptValue.length+1; i++) {
						var opt = new Option(aptValue[i-1].apartmentname,aptValue[i-1].apartmentid);
						s.options[i] = opt;
					}
					
				}
				
				/**
				* 公寓select框change函数
				*/
				function selectChange(){
					apartmentid = $("aptName").options[$("aptName").selectedIndex].value; //给apartmentid赋值
						//取到了对应apartmentid的楼层数目
						var aprt_floorno;
						var aprt_name;
						for(var m = 0; m<apartamount;m++){
							if(gaptInfo[m].apartmentid ==apartmentid){
							aprt_floorno = gaptInfo[m].apartmentfloornum;
							aprt_name = gaptInfo[m].apartmentname;
							break;
							}
						}
						var sf = $("floorName");
						DWRUtil.removeAllOptions(sf);  
						sf.options[0] = new Option("请选择楼层",'0');
						if(aprt_name == "七号楼"){
						for ( var j = 1; j < (parseInt(aprt_floorno)-1); j++) {
							var optt = new Option((j+2)+"层",(j+2));
							sf.options[j] = optt;
						}
						}
						else if(aprt_name == "三号楼"){
						for ( var j = 1; j < (parseInt(aprt_floorno)); j++) {
							var optt = new Option((j+1)+"层",(j+1));
							sf.options[j] = optt;
						}
						}
						else{
						for ( var j = 1; j < (parseInt(aprt_floorno)+1); j++) {
							var optt = new Option(j+"层",j);
							sf.options[j] = optt;
						}
						
						}
				}
		/**
		*点击搜索按钮时拼URL ，恐怖啊！ by lishuangjiang 3/21/2009
		*/
		
		function onsubmit(){
			var   ops=$("aptName").options; 
			var 	a1 =ops[$("aptName").selectedIndex].text; //a1是公寓名
			var 	a11 =ops[$("aptName").selectedIndex].value; //a11是index值
			//alert(a11)
			 if(a11==0){
					alert("请选择一个公寓");
					return "1";
			}
			var  opss=$("floorName").options; 
			var f1 = opss[$("floorName").selectedIndex].value; //f1是楼层数
			var d1 = $("dormName").value; //d1是宿舍名
			 
			if(a11==0&&f1==0){
				alert("请至少选择公寓名，或者公寓和楼层项");
				return "1";
			}
			 if((a11!="")&&f1==0&&(d1=="")){ //只是查询公寓
				 return DMS_ROOT+"/aptmgr/listSearchDorm.action?apartmentid="+a11+"&"+"dormitoryfloorno=0"; //直接返回宿舍列表，不要单个公寓列表
				//return DMS_ROOT+"/aptmgr/listByAptId.action?apartmentid="+a11;
			}else{
				return DMS_ROOT+"/aptmgr/listSearchDorm.action?apartmentid="+a11+"&"+"dormitoryfloorno="+f1+"&"+"dormitoryname="+d1;  
				}
		}
	function onAvailsubmit(){
			var   ops=$("aptName").options; 
			var 	a1 =ops[$("aptName").selectedIndex].text; //a1是公寓名
			var 	a11 =ops[$("aptName").selectedIndex].value; //a11是index值
			 if(a11==0){
					alert("请选择一个公寓");
					return "1";
			 }
			var  opss=$("floorName").options; 
			var f1 = opss[$("floorName").selectedIndex].value;
			if(f1==0){
				//alert("请选择一个楼层!");
				return DMS_ROOT+"/aptmgr/listSearchDormStatus.action?apartmentid="+a11+"&"+"dormitoryfloorno="+f1;
			}
			return DMS_ROOT+"/aptmgr/listSearchDormStatus.action?apartmentid="+a11+"&"+"dormitoryfloorno="+f1;
		}
		
		function onActionSubmit(){
			if(onsubmit()=="1"){
				return;
			}
			window.location.href=onsubmit(); 
		}

		function onSelectAvailActionSubmit(){
			if(onAvailsubmit()=="1"){
				return;
			}
			window.location.href=onAvailsubmit(); 
		}
			</script>
	</head>
	<body onLoad="javascript:setApartList()">
		<div id="page_container" style="height:auto;">
			<!-- 页面搜索div -->
			<div id="searchdiv">
				<table width="100%" border="0" cellspacing="1" cellpadding="0">
					<tr>
						<td height="49" bgcolor="ECECEC">
							<table width="93%" border="0" align="center" cellpadding="0"
								cellspacing="0">
								<tr>
									<td width="86%">
										<select name="aptName" id="aptName" style="width: 120"
											onchange="javascript:selectChange();">
										</select>
										&nbsp;
										<select name="floorName" id="floorName" onchange="onActionSubmit();" style="width: 120">
										</select>
										
										<input type="text" name="dormName" id="dormName" size="15" style="display:none"
											value="" class="Text" style="width:80px;">
									</td>
									<td width="4%">
										<a href="javascript:onActionSubmit();"><img
												src="<%=request.getContextPath()%>/images/ss.gif"> </a>
									</td>
									<td width="4%">
										<a href="javascript:onSelectAvailActionSubmit();"><img
												src="<%=request.getContextPath()%>/images/kx.gif"> </a>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</div>
			<!-- 页面搜索div 结束-->
			<!-- 循环显示宿舍情况div -->
			<div id="aptiterator">
				<s:iterator value="aptList">
					<div class="apartment" >
						<a href="<%=request.getContextPath()%>/aptmgr/listDormitory.action?apartmentid=${apartmentid}&dormitoryfloorno=0">
								<img
								src="<%=request.getContextPath()%>/images/boyapt/b1.jpg" 
								style="border:1px  solid white"
								onmouseover="this.style.border='1px groove black'"
								
								onmouseout="this.style.border='1px  solid white'" 
								width="120px" height="120px" 
								/>
						 </a>
						<div >
							<s:property value="apartmentname" />
							<br />
							总入住人数为：
							<s:property value="apartmenttotalrooms" />
							<br />
							可入住人数为：
							<s:property value="apartmentavailrooms" />
						</div>
					</div>
				</s:iterator>
			</div>
			<!-- 循环显示宿舍情况div结束 -->
		</div>
	</body>
</html>